// pages/clockDetail/clockDetail.js
const app = getApp()
const util = require('../../../../utils/util.js')
const lbbService = require('../../../service/service.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      cardDate: options.cardDate,
      uid: options.uid,
      type: options.type,
      nowDate:util.getNowDate(),
      scrollHeight:app.getScrollHeight(0)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let that = this
    that.personalModal = that.selectComponent("#personalModal")
    that.toast = that.selectComponent("#toast")
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getRecord()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  /**
   * 查看巡检报告
   */
  toReportDetail(e){
    console.log(e,'打印E')
    let id=e.currentTarget.dataset.id;
    let hospital = e.currentTarget.dataset.lbmid;
    wx.navigateTo({
      url: '/pages/patrolReport/patrolReport?reportId='+id+'&hospitalId='+hospital,
    })
  },
  
  /**
   * 删除打卡的某一个医院
   */
  removeSignHos: function(e){
    util.print('removeSignHos',e);
    let id = e.currentTarget.dataset.id;
    let lbmId = e.currentTarget.dataset.lbmId;
    let lbmName = e.currentTarget.dataset.lbmName;
    let that = this;
    
    that.personalModal.showModal('确定删除'+ lbmName +'吗', function(){
      lbbService.removeSignHos({
        punchCardId:id,
        lbmId:lbmId,
      },res => {
        that.getRecord();
      })
    });
  },
  /**
   * 获取打卡详情
   */
  getRecord:function(){
    let that = this
    lbbService.getCardDetail({
        type: parseInt(that.data.type),
        cardDate: that.data.cardDate,
        uid: that.data.uid
      },function(res){
        that.setData({
          signDetail: res.data,

        })
      })
  }
})